package be.vdab.aspects;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;

@Aspect
@Order(1)
public class Performance {
	@Around("be.vdab.aspects.PointcutExpressions.servicePointcut()")
	public Object getUitvoeringsTijd(ProceedingJoinPoint joinpoint) throws Throwable{
		long voor = System.nanoTime();
		System.out.println("timer voor join point:" + voor);
		Object returnValue = null;
		try{
			return returnValue = joinpoint.proceed();
		} finally {
			long na = System.nanoTime();
			System.out.println("timer na join point:" + na);
			Signature signature = joinpoint.getSignature();
			System.out.println(signature.toShortString() + " duurde " + (na-voor) + " nanosec.");
			System.out.println("return waarde:" + returnValue);
		}
	}
}
